package com.mk.common.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.mk.common.model.ItemData;
import com.mk.common.model.ReasonBO;

public class StreamDemo {

	@Test
	public void test1() {
		List<String> strings = Arrays.asList("abc", null, "bc", "efg", "abcd", "", "jkl");
		List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());

		filtered.forEach(System.out::println);
	}

	@Test
	public void test2() {
		List<String> arr = Arrays.asList("abc", null, "bc", "efg", "abcd", "", "jkl");
//		String res = arr.stream().collect(Collectors.joining("\r\n"));
		String res1 = arr.stream().collect(Collectors.joining("\r\n", "1、", ""));
		
		System.out.println(res1);
	}

	@Test
	public void test3() {
		List<String> strList = Arrays.asList("a", "ba", "bb", "abc", "cbb", "bba", "cab");
		Map<Integer, String> strMap = strList.stream()
				.collect(Collectors.toMap(str -> strList.indexOf(str), str -> str));

		strMap.forEach((key, value) -> {
			System.out.println(key + ", " + value);
		});
	}

	@Test
	public void test4() {
		Map<String, String> item1 = new HashMap<>();
		item1.put("JLXH", "1");
		item1.put("SJLX", "4");
		item1.put("LXMC", "非计划性拔管");
		item1.put("XMXH", "131");
		item1.put("XMMC", "一、意外拔管评估不到位");
		item1.put("MXXH", "320");
		item1.put("MXMC", "1）不会评估");
		Map<String, String> item2 = new HashMap<>();
		item2.put("JLXH", "1");
		item2.put("SJLX", "4");
		item2.put("LXMC", "非计划性拔管");
		item2.put("XMXH", "131");
		item2.put("XMMC", "一、意外拔管评估不到位");
		item2.put("MXXH", "323");
		item2.put("MXMC", "1）未正确评估");
		Map<String, String> item3 = new HashMap<>();
		item3.put("JLXH", "7");
		item3.put("SJLX", "4");
		item3.put("LXMC", "非计划性拔管");

		List<Map<String, String>> list = Arrays.asList(item1, item2, item3);
		// <记录主键， list>
		Map<Object, List<Map<String, String>>> idMap = list.stream()
				.collect(Collectors.groupingBy(ite -> ite.get("JLXH")));

//		idMap.forEach((key, val)->{
//			System.out.println(key+", "+val);
//		});
//		System.out.println(JSON.toJSONString(idMap));

		// <>
		idMap.forEach((key, val) -> {
			// <项目， list>
			Map<String, List<Map<String, String>>> typeMap = val.stream()
					.collect(Collectors.groupingBy(ite -> ite.get("XMXH")));

			Map<String, Object> pMap = new HashMap<>();
			List<Map<String, String>> pList = new ArrayList<>();
			typeMap.forEach((pid, arr) -> {
				Map<String, Object> baseMap = new HashMap<>();
				List<Map<String, String>> base = new ArrayList<>();
				arr.forEach(item -> {
					baseMap.put("name", item.get("XMMC"));
					String detailName = item.get("MXMC");
					item.clear();
					item.put("name", detailName);
					base.add(item);
				});
				baseMap.put("children", base);
			});
		});
	}

	@Test
	public void test5() {
		Map<String, String> item1 = new HashMap<>();
		item1.put("JLXH", "1");
		item1.put("SJLX", "4");
		item1.put("LXMC", "非计划性拔管");
		item1.put("XMXH", "131");
		item1.put("XMMC", "一、意外拔管评估不到位");
		item1.put("MXXH", "320");
		item1.put("MXMC", "1）不会评估");
		Map<String, String> item2 = new HashMap<>();
		item2.put("JLXH", "1");
		item2.put("SJLX", "4");
		item2.put("LXMC", "非计划性拔管");
		item2.put("XMXH", "131");
		item2.put("XMMC", "一、意外拔管评估不到位");
		item2.put("MXXH", "323");
		item2.put("MXMC", "1）未正确评估");
		Map<String, String> item3 = new HashMap<>();
		item3.put("JLXH", "7");
		item3.put("SJLX", "4");
		item3.put("LXMC", "非计划性拔管");
		List<Map<String, String>> list = Arrays.asList(item1, item2, item3);

		// 1、获取一组大骨
		Map<String, List<Map<String, String>>> bigMap = list.stream()
				.collect(Collectors.groupingBy(ite -> ite.get("JLXH")));
		// 最终结果集
		List<ItemData> resultList = new ArrayList<>(bigMap.size());
		bigMap.forEach((id, bList) -> {
			Map<String, String> first = bList.get(0);
			String eventTypeName = first.get("LXMC");

			ItemData<Map<String, String>> resultItem = new ItemData<>();
			resultItem.setName(eventTypeName);
			resultItem.setChildren(bList);
			resultList.add(resultItem); // 结果集加入
		});

		// 打印 TODO
		resultList.forEach(System.out::println);

	}

	@Test
	public void test6() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("1）不会评估");
		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("1）未正确评估");
		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");
		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);

		// 1、主键分组，大骨列表，事件类型
		Map<Long, List<ReasonBO>> bigMap = list.stream().collect(Collectors.groupingBy(it -> it.getId()));
		// 结果集
		List<ItemData> resultList = new ArrayList<>(bigMap.size());
//		bigMap.forEach((key, val) -> {
//			ItemData<ReasonBO> item = new ItemData<>();
//			item.setName(val.get(0).getEventTypeName());
//			item.setChildren(val);
//			resultList.add(item);
//		});
		//  项目分组
		bigMap.forEach((key, bigs) -> {
			ItemData bigItem = new ItemData<>();
			bigItem.setName(bigs.get(0).getEventTypeName());
			
			// 中骨，项目
			Map<Long, List<ReasonBO>> middleMap = bigs.stream().collect(Collectors.groupingBy(ite->ite.getProgramId()));
			List<ItemData> middleList = new ArrayList<>(middleMap.size());
			middleMap.forEach((pid, middles)->{
				ItemData<ItemData> middleItem = new ItemData<>();
				middleItem.setName(middles.get(0).getProgramName());
				
				Map<Long, List<ReasonBO>> smallMap = middles.stream().collect(Collectors.groupingBy(ite->ite.getDetailId()));
				List<ItemData> smallList = new ArrayList<>(smallMap.size());
				smallMap.forEach((did, smalls)->{
					ItemData smallItem = new ItemData();
					smallItem.setName(smalls.get(0).getDetailName());
					smallList.add(smallItem);
				});
				middleItem.setChildren(smallList);
				middleList.add(middleItem);
			});
			bigItem.setChildren(middleList);
			resultList.add(bigItem);
		});
		
		System.out.println(JSON.toJSON(resultList));
	}
	
	@Test
	public void test7() {
		/**
		 * 如果用 List<String> list = Arrays.asList("", "", null, "默认值"); 程序会报错
		 */
		List<String> list = new ArrayList<>(Arrays.asList("", "", null, "默认值"));
		list.removeIf(StringUtils::isEmpty);
		System.out.println(list.get(0));
		
		/**
		 * 测试正常
		 */
		LinkedList<String> linkList = new LinkedList<>(Arrays.asList("", "", null, "默认12值"));
		linkList.removeIf(StringUtils::isEmpty);
		System.out.println(linkList.get(0)); // 默认12值
		
	}
	
	@Test
	public void test8() {
		String res = Stream.of("", "2", null,"默认值").filter(e->!StringUtils.isEmpty(e)).findFirst().get();
		System.out.println(res); // 默认值
	}
	
	@Test
	public void test9() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("1）不会评估");
		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("1）未正确评估");
		
		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");
		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);
		
		Map<Integer, String> typeMap = list.stream()
				.filter(t->t.getEventType()!=null)
				.collect(Collectors.toMap(ReasonBO::getEventType, ReasonBO::getProgramName, (k1, k2)->k2));
		System.out.println(typeMap);
	}
	
	@Test
	public void test10() {
		List<String> strings = Arrays.asList("apple", "banana", "cherry");  
		IntStream intStream = strings.stream().mapToInt(String::length);  
		int maxLength = intStream.max().getAsInt();  
		System.out.println(maxLength); // 输出 6
	}
	
	@Test 
	public void test11() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("1）不会评估");
		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("1）未正确评估");
		
		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");
		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);
		
		
		List<String> names = list.stream().map(t->t.getDetailName()).collect(Collectors.toList());
		System.out.println(names);
		
		double as = 100;
		
	}

	
	@Test
	public void test12() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("不会评估");

		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("");

		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");

		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);

		int[] index = { 1 };
		List<ReasonBO> res = list.stream().filter(t -> t.getDetailName() != null && !"".equals(t.getDetailName()))
				.map(t -> {
					t.setDetailName(index[0] + "、" + t.getDetailName());
					index[0]++;
					return t;
				}).collect(Collectors.toList());

		res.forEach(System.out::println);
		System.out.println(Arrays.toString(index));
	}
	
	@Test
	public void test13() {
		ReasonBO reason = new ReasonBO();
		reason.setDetailId(12L);
		
		System.out.println(-reason.getDetailId());
	}
	
	@Test
	public void test14() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("不会评估");
		
		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("");
		
		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");
		
		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);

		String res = list.stream().map(ReasonBO::getProgramName).collect(Collectors.joining(","));
		System.out.println(res);
	}
	
	@Test
	public void test15() {
        List<String> dataList = Arrays.asList("1.根据2022年护理工作情况，组织病区护理质量与安全自查小组人员。",
                "2.完成每月护理质量与安全质量的自查。");
        
        List<ReasonBO> list = dataList.stream().map(u->{
        	ReasonBO re = new ReasonBO();
        	re.setEventTypeName(u);
        	return re;
        }).collect(Collectors.toList());
        
        list.forEach(System.out::println);
	}
	
	@Test
	public void test16() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("不会评估");
		
		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("");
		
		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");
		
		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);

		List<Integer> res = list.stream().map(u->u.getEventType())
				.distinct().collect(Collectors.toList());
		System.out.println( JSON.toJSON(res) ); // [4,11]
		
		Long num = list.stream().map(u->u.getEventType()).distinct().count();
		System.out.println(num);
	}

	@Test
	public void test17() {
		ReasonBO reason1 = new ReasonBO();
//		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("不会评估");
		
		ReasonBO reason2 = new ReasonBO();
//		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("");
		
		ReasonBO reason3 = new ReasonBO();
//		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");
		
		ReasonBO reason4 = new ReasonBO();
//		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);
		List<Long> ids = Arrays.asList(28L, 29L, 21L, 223L);
		
		int index = 0;
		list.forEach(item -> {
			int i = list.indexOf(item);
			item.setId(ids.get(i));
			System.out.println(item);
		});
	}
	
	@Test
	public void testDistinct() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);
		reason1.setProgramName("一、意外拔管评估不到位");
		reason1.setDetailId(320L);
		reason1.setDetailName("不会评估");

		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		reason2.setProgramId(132L);
		reason2.setProgramName("二、患者镇静镇痛评估不到位");
		reason2.setDetailId(323L);
		reason2.setDetailName("");

		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(11);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);
		reason3.setProgramName("护士");
		reason3.setDetailId(98L);
		reason3.setDetailName("护士查对内容不全");

		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		reason4.setProgramName("护士");
		reason4.setDetailId(99L);
		reason4.setDetailName("护士未双人查对");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);
		
		int[] index = {1}; 
		list.stream().filter(t->!StringUtils.isEmpty(t.getDetailName()))
			.map(u->{
				u.setDetailName(index+"、"+u.getDetailName());
				index[0]++;
				return u;
			})
			.collect(Collectors.toList());
	}
	
	/**
	 * 计数
	 */
	@Test
	public void testCountNum() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setId(1L);
		reason1.setEventType(4);
		reason1.setEventTypeName("计划性拔管");
		reason1.setProgramId(131L);

		ReasonBO reason2 = new ReasonBO();
		reason2.setId(1L);
		reason2.setEventType(4);
		reason2.setEventTypeName("计划性拔管");
		
		ReasonBO reason3 = new ReasonBO();
		reason3.setId(7L);
		reason3.setEventType(7);
		reason3.setEventTypeName("给药差错");
		reason3.setProgramId(29L);

		ReasonBO reason4 = new ReasonBO();
		reason4.setId(7L);
		reason4.setEventType(11);
		reason4.setEventTypeName("给药差错");
		reason4.setProgramId(29L);
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);
		
//		Map<Integer, Long> res = list.stream().collect(
//				Collectors.groupingBy(u->u.getEventType(), Collectors.counting())
//				);	
//		System.out.println(res);
		
		long num = list.stream().filter(t->t.getEventType()==7).count();
		System.out.println(num);
	}
	
	/**
	 * 交集。。。
	 */
	@Test
	public void testSubSet() {
		List<Integer> paramList = Arrays.asList(1,2,3,4,5);
		List<Integer> depts = Arrays.asList(6,8,9,144);
		
		List<Integer> result = Optional.ofNullable(paramList).filter(t->!t.isEmpty()).orElseGet(()->depts);
		List<Integer> res = depts.stream().filter(t->paramList.contains(t)).collect(Collectors.toList());
		System.out.println(JSON.toJSONString(result));
		System.out.println(JSON.toJSONString(res));
	}
	
	@Test
	public void testListConcat() {
		List<Integer> list1 = Arrays.asList(1,2,5,3);
		List<Integer> list2 = Arrays.asList();
		List<Integer> list3 = Arrays.asList(4,9);
		
		List<Integer> result = Stream.of(list1, list2, list3)
				.flatMap(Collection::stream).collect(Collectors.toList()); // [1, 2, 5, 3, 4, 9]
		
		System.out.println(result);
	}
	
	@Test
	public void testOrder() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setEventTypeName("2");
		
		ReasonBO reason2 = new ReasonBO();
		reason2.setEventTypeName("10");
		
		ReasonBO reason3 = new ReasonBO();
		reason3.setEventTypeName("1");
		
		ReasonBO reason4 = new ReasonBO();
		reason4.setEventTypeName("3");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);

		// 流操作
//		List<ReasonBO> records = list.stream().sorted(Comparator.comparing(ReasonBO::getEventTypeName)).collect(Collectors.toList());
//		records.forEach(System.out::println);
		
		// 自带的sort()方法
		list.sort(Comparator.comparing(ReasonBO::getEventTypeName));
//		list.sort(Comparator.comparingInt(Integer::parseInt::ReasonBO::getEventTypeName));
		list.forEach(System.out::println);
	}
	
	@Test
	public void testMergeToList() {
		String[] arr1 = {"23", "19", "11"};
		String[] arr2 = {"4", "0"};
		String[] arr3 = {"6", "12"};
		List<String> list = Stream.of(arr1, arr2, arr3).flatMap(Arrays::stream).collect(Collectors.toList());
		
		System.out.println(list);
	}
	
	/**
	 * 数组转成List
	 */
	@Test
	public void testArrayToList() {
		String[] arr1 = {"23", "19", "11"};
		List<String> list = Stream.of(arr1).collect(Collectors.toList());
		System.out.println(list); // [23, 19, 11]
	}
	
	
	@Test 
	public void testGetObj() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setEventTypeName("2");
		
		ReasonBO reason2 = new ReasonBO();
		reason2.setEventTypeName("10");
		
		ReasonBO reason3 = new ReasonBO();
		reason3.setEventTypeName("1");
		
		ReasonBO reason4 = new ReasonBO();
		reason4.setEventTypeName("3");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason3, reason4);
		
		ReasonBO res = list.stream().filter(t->"3".equals(t.getEventTypeName())).findFirst().get();
		System.out.println(res);
	}
	
	/**
	 * 数组列表为基准过滤一个List
	 */
	@Test 
	public void testArrayFilterList() {
		ReasonBO reason1 = new ReasonBO();
		reason1.setEventTypeName("2024-05-06");
		
		ReasonBO reason2 = new ReasonBO();
		reason2.setEventTypeName("2024-05-13");
		
		ReasonBO reason4 = new ReasonBO();
		reason4.setEventTypeName("2024-05-27");
		List<ReasonBO> list = Arrays.asList(reason1, reason2, reason4);
		
		List<String> dates = Arrays.asList("2024-04-29", "2024-05-06", "2024-05-13", "2024-05-20", "2024-05-27");
		
//		dates.stream().filter(t->t.equals());
	}
	
	
	@Test
	public void testSubList() {
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < 423; i++) {
			list.add(i);
		}

		int count = 70, len = list.size(), _num = len % count == 0 ? len / count : len / count + 1;
		for (int i = 0; i < _num; i++) {
			int b = i * count, e = (i + 1) * count;
//			System.out.println(b + ", " + e);
			List<Integer> subs = list.subList(b, e > len ? len : e);
			System.out.println(subs.size());
		}
	}
	

}
